import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.SwingConstants;

/**
 * View appointment panel for the patients.
 * @author ThunderDragon
 * @version 1.0
 *
 */
public class PatientViewAppointmentPanel extends JPanel {
	private JTable patientAppointmentTable;

	/**
	 * View appointment panel for the patients.
	 */
	public PatientViewAppointmentPanel() {
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblNewLabel = new JLabel("Upcoming Appointments:");
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel, 10, SpringLayout.NORTH, this);
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));
		add(lblNewLabel);
		
		patientAppointmentTable = new JTable();
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel, 0, SpringLayout.WEST, patientAppointmentTable);
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel, 0, SpringLayout.EAST, patientAppointmentTable);
		springLayout.putConstraint(SpringLayout.WEST, patientAppointmentTable, 35, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, patientAppointmentTable, 425, SpringLayout.WEST, this);
		patientAppointmentTable.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				"Date", "Time", "Doctor Name", "Reason"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, String.class, String.class, String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		patientAppointmentTable.getColumnModel().getColumn(2).setPreferredWidth(120);
		patientAppointmentTable.getColumnModel().getColumn(3).setPreferredWidth(120);
		patientAppointmentTable.setSurrendersFocusOnKeystroke(true);
		patientAppointmentTable.setFillsViewportHeight(true);
		patientAppointmentTable.setColumnSelectionAllowed(true);
		patientAppointmentTable.setCellSelectionEnabled(true);
		add(patientAppointmentTable);
		
		JLabel lblNewLabel_1 = new JLabel("Date");
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 35, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.NORTH, patientAppointmentTable, 6, SpringLayout.SOUTH, lblNewLabel_1);
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 30, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, 44, SpringLayout.SOUTH, lblNewLabel);
		add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Time");
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, -6, SpringLayout.WEST, lblNewLabel_2);
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_2, 30, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_2, 44, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_2, 107, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_2, 173, SpringLayout.WEST, this);
		add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Doctor Name");
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_3, 30, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_3, 13, SpringLayout.EAST, lblNewLabel_2);
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_3, 44, SpringLayout.SOUTH, lblNewLabel);
		add(lblNewLabel_3);
		
		JLabel lblNewLabel_4 = new JLabel("Reason");
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_3, -56, SpringLayout.WEST, lblNewLabel_4);
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_4, 30, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_4, 44, SpringLayout.SOUTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_4, 366, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_4,
				304, SpringLayout.WEST, this);
		add(lblNewLabel_4);
	}
	
	/**
	 * Set the date at the corresponding index.
	 * @param date The specified date.
	 * @param index The specified index.
	 */
	public void setDate(String date, int index){
		patientAppointmentTable.setValueAt(date, index, 0);
	}
	
	/**
	 * Set the time at the corresponding index.
	 * @param time The specified time.
	 * @param index The specified index.
	 */
	public void setTime(String time, int index){
		patientAppointmentTable.setValueAt(time, index, 1);
	}
	
	/**
	 * Set the doctor's name at the specified index.
	 * @param doctorName The specified doctor's name.
	 * @param index The specified index.
	 */
	public void setDoctorName(String doctorName, int index){
		patientAppointmentTable.setValueAt(doctorName, index, 2);
	}
	
	/**
	 * Set the reason at the specified index.
	 * @param reason The specified reason.
	 * @param index The specified index.
	 */
	public void setReason(String reason, int index){
		patientAppointmentTable.setValueAt(reason, index, 3);
	}
}
